package org.example.mapping;

import org.example.dto.Food;
import org.example.dto.FoodDetails;
import org.example.dto.Potato;
import org.example.utils.StrUtil;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring",imports = {StrUtil.class})
public interface FoodMapping {

    @Mapping(target = "name", source = "name")
    @Mapping(target = "potatoDetail.color", source = "details.color")
    @Mapping(target = "detail",expression = "java( StrUtil.toStr(food.getDetails().getUses()) )")
    Potato foodToPotato(Food food);

    @Mapping(target = "name", source = "name")
//    @Mapping(target = "details.color", source = "potatoDetail.color")
    @Mapping(target = "details.uses",expression = "java( StrUtil.toSet(potato.getDetail()) )")
    @Mapping(target = "details.color",expression = "java( potato.getPotatoDetail().getColor() )")
    Food potatoToFood(Potato potato);

}
